package com.qiyadeng.wechat.roo.model;
import java.util.List;

import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "LOCAL_USER")
@RooDbManaged(automaticallyDelete = true)
public class LocalUser {
	
	//保存用户
	public static void saveLocalUser(String userName,String identifyNo,String phone,String email,String wechatuser){
		List<LocalUser> list = entityManager().createQuery("select o from LocalUser o where o.userPhone=?1", LocalUser.class)
				.setParameter(1, phone)
				.getResultList();
		if(list.size()>0){
			return;//已经存在则不保存
		}
		LocalUser user = new LocalUser();
		user.setUserName(userName);
		user.setIdNo(identifyNo);
		user.setUserPhone(phone);
		user.setEmail(email);
		user.setWechatId(wechatuser);
		user.persist();
	}
	
	public static void updateLocalUserCard(String phone,String card){
		List<LocalUser> list = entityManager().createQuery("select o from LocalUser o where o.userPhone=?1", LocalUser.class)
		.setParameter(1, phone)
		.getResultList();
		if(list.size()>0){
			list.get(0).setCard(card);
		}
	}
}
